import axios from 'axios'

import { getToken} from '@/utils/token.js'


let instance = axios.create({
  baseURL : 'http://api-toutiao-web.itheima.net/',
  timeout : 5000
})

//请求拦截器 
instance.interceptors.request.use((config)=> {
   let token = getToken()
   if (token) {
     config.headers.Authorization = 'Bearer ' + token
   }
   return config
})

//响应拦截器
instance.interceptors.response.use(res=> {
   return res
})

export default instance